import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

public class Thread_FixedThreadPool {
	private static ThreadPoolExecutor executor = null;

	public static void main(String[] args) throws InterruptedException {
		System.out.println("xxx");
		executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(10);
		Thread thread = null;
		for (int i = 0; i < 9; i++) {
			thread = initThread(i);
			executor.execute(thread);
			// Thread.sleep(100);
			// System.out.println(executor.getTaskCount() + "-.....");
			// System.out.println("====add for " + i);
		}
		// executor.shutdown();
	}

	public static Thread initThread(final long id) {
		return new Thread(new Runnable() {
			@Override
			public void run() {
				try {
					Thread.sleep(1000);
					System.out.println(Thread.currentThread().getName() + " for id:" + id + "--->" + executor.getActiveCount());
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		});
	}

}
